|
|
|
|
|
|
|
input. After invoking AddNew, your program can populate the fields by treating them like variables. Finally, to add the record physically after you put data into the record's fields, use the Update method. The following lines of code illustrate this technique: |
|
|
|
|
|
|
|
|
'Prepare a new record in the copy buffer
rsTest.AddNew
'Populate the new record's fields
rsTest!FirstName = "Casey"
rsTest!LastName = "Jones"
'"Save" the changes with Update
rsTest.Update |
|
|
|
|
CAUTION
|
|
|
|
|
Because AddNew places information only in the copy buffer, reusing the AddNew method or moving the record pointer with any Move or Find method (before using the Update method) clears the copy buffer. Any information entered in the new record up to that point is therefore lost. |
|
|
|
|
|
|
|
|
|
|
In a manner similar to adding a record, you use the Edit method to make changes to a record. The Edit method places a copy of the current record's contents into the copy buffer so that information can be changed. As with AddNew, the changes take effect only when the Update method is executed. |
|
|
|
|
|
|
|
|
To edit a record, first provide a way for the users to locate the record that they want to modify. You can use one or more of the techniques described earlier in this chapter to accomplish this task. After you locate the record you want (and make it the current record), invoke the Edit method. Then you can populate the fields (most likely obtaining the new information from the users) and finally invoke the Update method. This technique is illustrated in the following lines of code: |
|
|
|
|
|
|
|
|
rsTest.Edit
rsTest!FirstName = txtFirstName.Text
rsTest!LastName = txtLastName.Text
rsTest.Update |
|
|
|
|
CAUTION
|
|
|
|
|
Because Edit only places information in the copy buffer, reusing the Edit method or moving the record pointer with any Move or Find method (before using the Update method) clears the copy buffer. Any information entered in the record is therefore lost. |
|
|
|
|
|
|
|
|
|
|
As you learned in the previous two sections, you use the Update method in conjunction with the AddNew and Edit methods to make changes to the recordsets. The Update method writes |
|
|
|
|
|